﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using NL.ADA.AdminService;
using System.ServiceModel;
using NL.ADA.Common;
using NL.ADA.ConfigService.DAL.TypedListClasses;
using NL.ADA.ConfigService.DAL.HelperClasses;
using NL.ADA.ConfigService.DAL.EntityClasses;

namespace NUnit
{
    public class AdminServiceGateway : IDisposable
    {

        private IAdminService _service;
        private ChannelFactory<IAdminService> _channelFactory;

        public AdminServiceGateway()
        {
            _channelFactory = new ChannelFactory<IAdminService>("WSHttpBinding_IAdminService");
            _service = _channelFactory.CreateChannel();

        }
        public CustomConfig GetConfigById(int id)
        {
            return _service.GetConfigById(id);
        }

        public CustomConfig GetConfigByKey(string key, int appId, int modeId)
        {
            return _service.GetConfigByKey(key, appId, modeId);
        }

        public int InsertConfig(int configId, int modeId, string key, string value, int applicationId, string applicationCode, int configTypeId)
        {
            var config = new CustomConfig();
            config.ConfigId = configId;
            config.ModeId = modeId;
            config.Key = key;
            config.Value = value;
            config.ApplicationId = applicationId;
            config.ConfigTypeId = configTypeId;
            return _service.InsertConfig(config);

        }

        public void Dispose()
        {
            if (_channelFactory != null)
                _channelFactory.Close();
        }


    }
}
